/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       simple_dialog.cpp

	$Header: /game/simple_dialog.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "simple_dialog.h"

#include "adaptor_handler.h"
#include "basic_dialog.h"
#include "button.h"
#include "button_bitmaps.h"
#include "button_cache.h"
#include "function_handler.h"
#include "item_help_block.h"
#include "platform.h"
#include "popup_window.h"


// --------------------------------------------------------
// put up a simple dialog with an OK button
// --------------------------------------------------------
void ok_dialog( std::string const& text, t_screen_point point, std::string const& title )
{
	point = t_window::get_main_window()->to_client( point );

	t_counted_ptr<t_basic_dialog> dialog = new t_basic_dialog;

	dialog->add_ok_button();
	dialog->set_text( text );
	dialog->set_title( title );
	dialog->open( point, true, k_align_bottom );

	dialog->run_modal();
}

void ok_dialog( std::string const& text, bool centered, std::string const& title )
{
	t_screen_point point;

	if (centered)
	{
		t_screen_rect rect = t_window::get_main_window()->get_screen_rect();

		point.x = (rect.left + rect.right) / 2;
		point.y = (rect.top + rect.bottom) / 2;
	}
	else
		point = get_mouse_screen_position();
	ok_dialog( text, point, title );
}

bool yes_no_dialog( std::string const& text, t_screen_point point )
{
	point = t_window::get_main_window()->to_client( point );

	t_counted_ptr<t_basic_dialog> dialog = new t_basic_dialog;

	dialog->add_cancel_button();
	dialog->set_text( text );
	dialog->add_ok_button();
	dialog->open( point, true, k_align_bottom );

	return dialog->run_modal() != 0;
}

bool yes_no_dialog( std::string const& text, bool centered )
{
	t_screen_point point;

	if (centered)
	{
		t_screen_rect rect = t_window::get_main_window()->get_screen_rect();

		point.x = (rect.left + rect.right) / 2;
		point.y = (rect.top + rect.bottom) / 2;
	}
	else
		point = get_mouse_screen_position();

	return yes_no_dialog( text, point );
}

// -----------------------------------------------------------------
// show a popup dialog with text information, near point
// -----------------------------------------------------------------
void show_popup_text( std::string text, t_window* parent, t_screen_point point )
{
	t_window*       window;
	t_window*       modal_window = t_window::get_main_window();
	t_basic_dialog* dialog;

	point = modal_window->to_client( point );
	window = new t_popup_window( point, modal_window );
	window->set_cursor( parent->get_cursor( false ));
	dialog = new t_basic_dialog( window );

	assert( !text.empty() );
	text[0] = toupper( text[0] );
	dialog->set_text( text );
	dialog->open( t_screen_point(0,0), modal_window->get_client_rect() - point, 
		          true, k_align_top );
	window->fit_to_parent_rect();
}

// -----------------------------------------------------------------
// show a popup dialog with text information, near point
// -----------------------------------------------------------------
void show_popup_text( std::string text, t_screen_point point )
{
	t_window*       modal_window = t_window::get_main_window();

	show_popup_text( text, modal_window, point );
}

// -----------------------------------------------------------------
// show a popup dialog with text information, near parent window
// -----------------------------------------------------------------
void show_popup_text( std::string text, t_window const* parent )
{
	t_screen_rect   rect = parent->get_screen_rect();
	t_screen_point  point( (rect.left + rect.right) / 2, rect.bottom);

	show_popup_text( text, point );
}

